#include <stdio.h>
int main()
{
    int num;
    while( scanf("%d", &num) != EOF ){
        int nuits = num % 10;
        if( nuits == 6 && num % 6 == 0)
            printf("%d\n", num);
        else
            printf("illegal\n");
    }
    return 0;
}